<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章添加--layui后台管理模板</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <script src="../../jquery-3.3.1/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="../../../layui-v2.2.6/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css" media="all" />

    <script src="../../jquery-3.3.1/jquery-3.3.1.js"></script>

    <script type="text/javascript" src="../../../tool/ajax.js"></script>
</head>
<body class="childrenBody">
<form class="layui-form" style="display: flex;flex-direction: column;align-content: center;margin-top: 20px">
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">ID</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="text" id="id" class="layui-input newsName" lay-verify="required"  style="width: 400px" >-->
        <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" class="layui-input newsName" lay-verify="required"  style="width: 400px" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价值</label>
        <div class="layui-input-block">
            <input type="text" id="price" class="layui-input newsName" lay-verify="required"  style="width: 400px" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" id="type" class="layui-input newsName" lay-verify="required"
                   style="width: 400px"   placeholder="1普通奖励,2高等奖励"  onkeyup="(this.v=function(){this.value=this.value.replace(/[^1-2-]+/,'');}).call(this)" onblur="this.v();">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">奖励阶段</label>
        <div class="layui-input-block">
            <input type="text" id="phase" class="layui-input newsName" lay-verify="required"
                   style="width: 400px"  onkeyup="(this.v=function(){this.value=this.value.replace(/[^1-3-]+/,'');}).call(this)" onblur="this.v();"
                   placeholder="1,2,3">
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">匹配规则</label>
        <div class="layui-input-block">
            <input type="text" id="rule"  placeholder="请填大写字母"    class="layui-input newsName" lay-verify="required"
                   style="width: 400px"  >
        </div>
    </div>
    <div class="layui-upload" style="margin-left: 60px">
        <button type="button" class="layui-btn layui-btn-normal" id="test8">批量导入规则</button>
        <button type="button" class="layui-btn" id="test9">开始上传</button>
        <p id="demoText"></p>
    </div>


    <i style="margin-left: 10%;color: #e60000">注：奖励阶段为1对应的匹配规则为5个如：AAAAA，阶段为2对应选项7个，阶段3对应选项为10个，注意选项需要大写字母，请勿写多或写少。

    </i>

    <button type="button" align="center"  onclick="editpro()"  style="width:30%;margin: 0 auto;" class="layui-btn layui-btn-normal layui-btn-radius">提交信息
    </button>

</form>
<script type="text/javascript" src="../../../layui-v2.2.6/layui/layui.js" ></script>


</body>
<script>
    function editpro() {
        // var id = document.getElementById("id").value;
        var name = document.getElementById("name").value;
        var price = document.getElementById("price").value;
        var type=document.getElementById("type").value;
        var phase=document.getElementById('phase').value
        var rule=$("#rule").val();
        if(rule==""||rule==null){
            rule=$("#demoText").val();
        }

        ajaxpost("/index/award/admin/add", { name:name, price:price,type:type,phase:phase,rule:rule}, function (data) {
            try {

                if (data.code == 200) {
                    layer.msg('添加成功', {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        parent.location.reload();
                    });
                } else {
                    layer.msg('添加失败', {
                        icon: 0,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {

                        parent.location.reload();
                    });
                }
            } catch (e) {
                layer.msg('添加失败', {
                    icon: 0,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    parent.location.reload();
                });
            }
        })
    }

    layui.use('upload', function(){


        var $ = layui.jquery
            ,upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#test8'
            ,url: 'http://ty108.com/answer/upload/file'
            ,auto: false
            ,bindAction: '#test9',
            accept: 'file'
            ,done: function(res){
                //如果上传失败
                if(res.code ==200){
                    $("#demoText").val(res.data.path)
                    return layer.msg('上传成功');

                }else {
                    return layer.msg('上传失败');
                }
                //上传成功
            }

            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                // obj.preview(function(index, file, result){
                //     $('#img').attr('src', result); //图片链接（base64）
                // });
            }

            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });

</script>
</html>